package me.report.api.web.controller.api;

//import iwin.vn.api.jdbc.service.JdbcService;
import me.report.api.mongodb.service.MongoService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import me.report.api.web.util.Constant;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class HomeController {

//    @Autowired
//    JdbcService jdbcService;
    @Autowired
    MongoService mongoService;
    Logger logger = Logger.getLogger(getClass());

    @RequestMapping(value = {"", "/"})
    public @ResponseBody
    ModelAndView index(HttpServletRequest request, HttpServletResponse response) {
        //ApiWebService.getInstance().setService(mongoService, jdbcService);
        String control = request.getParameter(Constant.CONTROL);
        String func = request.getParameter(Constant.FUNC);
        //logger.debug("request.getQueryString(): " + request.getQueryString());
        
        
        return new ModelAndView("forward:/api/" + control + "/" + func + "?" + request.getQueryString());
        
    }
    
    @RequestMapping(value = {"/test"})
    public @ResponseBody
    String test(HttpServletRequest request, HttpServletResponse response) {
        //ApiWebService.getInstance().setService(mongoService, jdbcService);
        logger.debug("request.getQueryString(): " + request.getQueryString());
        return "done";
        
    }
}
